namespace {
constexpr auto settingsAccountsC = "Accounts";
constexpr auto settingsFoldersC = "Folders";
+constexpr auto settingsFoldersWithPlaceholdersC = "FoldersWithPlaceholders";
constexpr auto settingsVersionC = "version";
constexpr auto maxFoldersVersion = 1;
return;
}
- settings.beginGroup(settingsAccountsC);
- qCDebug(lcFolderMan) << "try to migrate accountId:" << accountState->account()->id();
- settings.beginGroup(accountState->account()->id());
- settings.beginGroup(settingsFoldersC);
-
- if (settings.childGroups().isEmpty()) {
- qCDebug(lcFolderMan) << "there are no legacy folders for accountId:" << accountState->account()->id();
- return;
- }
-
- const auto childGroups = settings.childGroups();
- for (const auto &alias : childGroups) {
- settings.beginGroup(alias);
- qCDebug(lcFolderMan) << "try to migrate folder alias:" << alias;
-
- const auto path = settings.value(QLatin1String("localPath")).toString();
- const auto targetPath = settings.value(QLatin1String("targetPath")).toString();
- const auto journalPath = settings.value(QLatin1String("journalPath")).toString();
- const auto paused = settings.value(QLatin1String("paused"), false).toBool();
- const auto ignoreHiddenFiles = settings.value(QLatin1String("ignoreHiddenFiles"), false).toBool();
-
- if (path.isEmpty()) {
- qCDebug(lcFolderMan) << "localPath is empty";
- settings.endGroup();
- continue;
- }
-
- if (targetPath.isEmpty()) {
- qCDebug(lcFolderMan) << "targetPath is empty";
- settings.endGroup();
- continue;
+ auto migrateFoldersGroup = [&](const QString &folderGroupName) {
+ const auto childGroups = settings.childGroups();
+ if (childGroups.isEmpty()) {
+ qCDebug(lcFolderMan) << "There are no" << folderGroupName << "to migrate from account" << accountState->account()->id();
+ return;
}
+ for (const auto &alias : childGroups) {
+ settings.beginGroup(alias);
+ qCDebug(lcFolderMan) << "try to migrate" << folderGroupName << "alias:" << alias;
+
+ const auto path = settings.value(QLatin1String("localPath")).toString();
+ const auto targetPath = settings.value(QLatin1String("targetPath")).toString();
+ const auto journalPath = settings.value(QLatin1String("journalPath")).toString();
+ const auto paused = settings.value(QLatin1String("paused"), false).toBool();
+ const auto ignoreHiddenFiles = settings.value(QLatin1String("ignoreHiddenFiles"), false).toBool();
+
+ if (path.isEmpty()) {
+ qCDebug(lcFolderMan) << "localPath is empty";
+ settings.endGroup();
+ continue;
+ }
- if (journalPath.isEmpty()) {
- qCDebug(lcFolderMan) << "journalPath is empty";
- settings.endGroup();
- continue;
- }
+ if (targetPath.isEmpty()) {
+ qCDebug(lcFolderMan) << "targetPath is empty";
+ settings.endGroup();
+ continue;
+ }
- FolderDefinition folderDefinition;
- folderDefinition.alias = alias;
- folderDefinition.localPath = path;
- folderDefinition.targetPath = targetPath;
- folderDefinition.journalPath = journalPath;
- folderDefinition.paused = paused;
- folderDefinition.ignoreHiddenFiles = ignoreHiddenFiles;
-
- if (const auto folder = addFolderInternal(folderDefinition, accountState, std::make_unique<VfsOff>())) {
- auto ok = true;
- auto legacyBlacklist = folder->journalDb()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList,
- &ok);
- if (!ok) {
- qCInfo(lcFolderMan) << "There was a problem retrieving the database selective sync for " << folder;
+ if (journalPath.isEmpty()) {
+ qCDebug(lcFolderMan) << "journalPath is empty";
+ settings.endGroup();
+ continue;
}
- legacyBlacklist << settings.value(QLatin1String("blackList")).toStringList();
- if (!legacyBlacklist.isEmpty()) {
- qCInfo(lcFolderMan) << "Legacy selective sync list found:" << legacyBlacklist;
- for (const auto &legacyFolder : legacyBlacklist) {
- folder->migrateBlackListPath(legacyFolder);
+ qCDebug(lcFolderMan) << folderGroupName << "located at" << path;
+
+ FolderDefinition folderDefinition;
+ folderDefinition.alias = alias;
+ folderDefinition.localPath = path;
+ folderDefinition.targetPath = targetPath;
+ folderDefinition.journalPath = journalPath;
+ folderDefinition.paused = paused;
+ folderDefinition.ignoreHiddenFiles = ignoreHiddenFiles;
+
+ if (const auto folder = addFolderInternal(folderDefinition, accountState, std::make_unique<VfsOff>())) {
+ auto ok = true;
+ auto legacyBlacklist = folder->journalDb()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList,
+ &ok);
+ if (!ok) {
+ qCInfo(lcFolderMan) << "There was a problem retrieving the database selective sync for " << folder;
+ }
+
+ legacyBlacklist << settings.value(QLatin1String("blackList")).toStringList();
+ if (!legacyBlacklist.isEmpty()) {
+ qCInfo(lcFolderMan) << "Legacy selective sync list found:" << legacyBlacklist;
+ for (const auto &legacyFolder : legacyBlacklist) {
+ folder->migrateBlackListPath(legacyFolder);
+ }
+ settings.remove(QLatin1String("blackList"));
}
- settings.remove(QLatin1String("blackList"));
- }
- folder->saveToSettings();
+ folder->saveToSettings();
- qCInfo(lcFolderMan) << "Migrated!" << folder->path();
- settings.sync();
+ qCInfo(lcFolderMan) << "Migrated!" << folder->path();
+ settings.sync();
- if (!folder) {
- continue;
- }
+ if (!folder) {
+ continue;
+ }
- scheduleFolder(folder);
- emit folderSyncStateChange(folder);
+ scheduleFolder(folder);
+ emit folderSyncStateChange(folder);
+ }
+ settings.endGroup(); // folder alias
}
+ };
- settings.endGroup();
- }
+ settings.beginGroup(settingsAccountsC);
+ qCDebug(lcFolderMan) << "try to migrate accountId:" << accountState->account()->id();
+ settings.beginGroup(accountState->account()->id());
+ settings.beginGroup(settingsFoldersWithPlaceholdersC);
+ migrateFoldersGroup(settingsFoldersWithPlaceholdersC);
settings.endGroup();
+
+ settings.beginGroup(settingsFoldersC);
+ migrateFoldersGroup(settingsFoldersC);
settings.endGroup();
+ settings.endGroup();
+ settings.endGroup();
return;
}